#ifndef OBJMesh_h__
#define OBJMesh_h__

#include "../../Base/Vertex.h"
#include "../../Forest/TreeNode.h"
#include <map>
class NxActor;
class Skeleton;
class EffectAnim;

struct FaceInfo
{
	int vertex;
	int normal;
	int texcoord;
	bool operator== (const FaceInfo& other)
	{
		if(this->vertex == other.vertex && this->normal == other.normal && this->texcoord == other.texcoord)
			return true;
		else
			return false;
	}
};

/** 
* Deze klasse leest OBJ bestanden in en toont ze.
* @author Ruben Rigole
* @todo Afwerken
* @bug Verkeerde TextureCoordinaten
*/
class OBJMesh: public TreeNode
{
public:
	/** 
	* Constructor
	* @param mDesc Geeft de descriptor door.
	* @param pos De positie.
	* @param rot De rotatie.
	* @param scale De scaling.
	*/
	OBJMesh(const MeshDesc& mDesc, const D3DXVECTOR3& pos = D3DXVECTOR3(0, 0, 0), const D3DXVECTOR3& rot = D3DXVECTOR3(0, 0, 0), const D3DXVECTOR3& scale = D3DXVECTOR3(1, 1, 1));
	virtual ~OBJMesh();

	void Draw(EffectShadow* effect, int step);
	void Init(const MeshDesc& mDesc);
	//void SetSkeleton(const Skeleton* skel);

	const ID3D10ShaderResourceView* GetTexture() const;

private:
	vector<D3DXVECTOR3> m_Vertices;
	//vector<D3DXVECTOR4> m_BoneId;
	//vector<D3DXVECTOR4> m_BoneWeight;
	vector<D3DXVECTOR3> m_Normals;
	vector<D3DXVECTOR2> m_TexCoords;
	vector<FaceInfo> m_Faces;

	const Skeleton* m_Skeleton;

	D3DXVECTOR3 m_MinPos, m_MaxPos;
	tstring m_TextureFile;

	vector<VertexAnim> m_VertexList;
	vector<int> m_IndexList;

	AABB m_BoundingBox;
	EffectAnim* m_Effect;

	ID3D10InputLayout *m_Layout;

	ID3D10ShaderResourceView* m_Texture;

	ID3DX10Mesh* m_Mesh;

	// Private functions
	void ReadVertice(tstring& line);
	void ReadNormal(tstring& line);
	void ReadTexture(tstring& line);
	void ReadFaces(tstring& line);
	void CalculateMesh();
	void ReadMaterial(tstring& line);
	void ReadMaterialFile(tstring& file);

	OBJMesh(const OBJMesh &t);
	OBJMesh& operator= (const OBJMesh &t);
};

#endif // OBJMesh_h__